#!/bin/bash

curpath=`pwd`

function backup_old_config()
{
    mv $1 $1.bak
}

backup_old_config "~/.emacs.d" 
let count=0
while true;do
    if [ ! -f spacemacs/init.el ];then
        git clone https://github.com/syl20bnr/spacemacs.git $curpath/spacemacs
        if [ $? == 0 ];then
            break
        fi
    else
        break
    fi
    let count=$count+1
    if [ $count -eq 10 ];then
        echo "Download Failed!!!"
        exit
    fi
done

backup_old_config "~/.emacs.d"
ln -s $curpath/spacemacs ~/.emacs.d

backup_old_config "~/.emacs"

backup_old_config "~/.gitconfig"

ln -s $curpath/.gitconfig ~/.gitconfig
echo export GTAGSLABEL=pygments >> ~/.profile
